package com.controller.library;

import java.io.IOException;
import java.io.UnsupportedEncodingException;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.action.library.SRegisterAction;
import com.bean.library.Student;

public class SRegisterServlet extends HttpServlet{
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	public void doPost(HttpServletRequest request,HttpServletResponse response){
		try {
			request.setCharacterEncoding("utf-8");
		} catch (UnsupportedEncodingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		String studentId = request.getParameter("student_id");
		String password = request.getParameter("password");
		String studentName = request.getParameter("student_name");
		String academy = request.getParameter("academy");
		String major = request.getParameter("major");
		String yearOfEntrance = request.getParameter("year_of_entrance");
		
		SRegisterAction sRegisterAction = new SRegisterAction();
		//Student student = sRegisterAction.studentRegister(studentId, password, 
			//				studentName, academy, major, yearOfEntrance);
		System.out.println("接受注册的参数：--");
		System.out.println("id--"+studentId);
		System.out.println("name--"+studentName);
		System.out.println("password--"+password);
		System.out.println("academy--"+academy);
		System.out.println("major--"+major);
		System.out.println("yearOfEntrance--"+yearOfEntrance);
		
		Student studentRegist = new Student(studentId,studentName,password,academy,major,yearOfEntrance);
		Student student = sRegisterAction.studentRegister(studentRegist);
		
		if(student!=null){
			//注册成功后的动作有两种方式，一种手动登录，一种是自动登录
//			try {
//				response.sendRedirect("/Exam1/student/page/index.htm");
//			} catch (IOException e) {
//				e.printStackTrace();
//			}
			
//			request.getSession().setAttribute("student", student);
//			try {
//				response.sendRedirect("/Exam1/student/page/welcome.jsp");
//			} catch (IOException e) {
//				e.printStackTrace();
//			}
		}
	}
}
